package com.stx.xhb.customwaterview.slice;

import com.stx.xhb.customwaterview.ResourceTable;
import com.stx.xhb.customwaterview.ToastUtils;

import com.stx.xhb.customwaterview.WaterFlake;
import com.stx.xhb.customwaterview.model.WaterModel;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;

import java.util.ArrayList;
import java.util.List;

public class MainAbilitySlice extends AbilitySlice {
    private WaterFlake mWaterFlake;
    private Button mBtn;
    private List<WaterModel> mModelList;
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        mWaterFlake = (WaterFlake) findComponentById(ResourceTable.Id_custom_view);
        mBtn = (Button) findComponentById(ResourceTable.Id_btn);
        mWaterFlake.setOnWaterItemListener(new WaterFlake.OnWaterItemListener() {
            @Override
            public void onItemClick(WaterModel pos) {
                ToastUtils.showToast(getContext(), "点击了");
            }
        });
        initData();
        mBtn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                initData();
            }
        });
    }

    private void initData() {
        mModelList = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            mModelList.add(new WaterModel("sds"));
        }

        mWaterFlake.setModelList(mModelList, mBtn);


    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
